/*
 * @Description:
 * @version:
 * @Author: 尹鹏孝
 * @Date: 2023-07-08 16:02:28
 * @LastEditors: 尹鹏孝
 * @LastEditTime: 2024-03-11 17:04:08
 */
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './filters/HttpExceptionFilter.filter'
import { AllExceptionsFilter } from './filters/AllExceptionsFilter.filter'
import { TransformInterceptor } from './interceptor/transform.interceptor';
import * as session from "express-session";
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { SESSION_SECRET } from './config/constant'
import { CustomLogger } from './custom-logger/custom-logger.service'
import { NestExpressApplication } from '@nestjs/platform-express';


import { join } from 'path';
const port = 1988;
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule,

    // {
    //  logger: new CustomLogger(),
    // }

  );
    //全局注册过滤器
  // app.useGlobalFilters(new HttpExceptionFilter, new AllExceptionsFilter());
  // 全局注册拦截器
  // app.useGlobalInterceptors(new TransformInterceptor());
  app.setBaseViewsDir(join(__dirname, '..', 'views'));
  // app.useStaticAssets(join(__dirname, '..', 'public'),{
  //   prefix: '/static/',   //设置虚拟路径
  // });
  app.setViewEngine('ejs');
  // app.useLogger(new CustomLogger());

  app.setGlobalPrefix("api")
  app.use(session({ secret: SESSION_SECRET, rolling: false, resave: false,saveUninitialized:true, name: "My.sid" }))
  // app.enableCors({
  //   origin: "http://localhost:3000",
  //   credentials:true,
  // })

   // 设置swagger文档
  const config = new DocumentBuilder()
    .setTitle('管理后台')
    .setDescription('管理后台接口文档')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);
  await app.listen(port);
  console.log(`http://localhost:${port}`)
  console.log(`swagger:http://localhost:${port}/docs/#/`)
}
bootstrap();

